﻿@model List<LynxWiki.DomainModel.SearchData>

@using AuthorizeAction;

@{
    ViewBag.Title = "Wiki Local Search";
}

<h2>Wiki Local Search</h2>

@using (Html.BeginForm("Index", "Search", FormMethod.Post, new { DefaultButton = "submitSrch", id = "SrchForm" })) {
<fieldset>
    <legend></legend>
    <label for="txtSrchTerm" class="inline" >Query: </label>
    <input type="radio" id="rb1" name="toggler" value="1" checked="checked" />Wiki Text
    <input type="radio" id="rb2" name="toggler" value="2" />Attachments<br />
    <input type="search" name="txtSrchTerm" id="txtSrchTerm" value="@ViewBag.SrchTerm"  />
    <label for="txtSrchFld" class="inline" >Field (optional):</label>
    <span id="blk-1" class="toHide inline">@Html.DropDownList("txtSrchFld", (IEnumerable<SelectListItem>) ViewBag.WikiFlds, "")</span>
    <span id="blk-2" class="toHide inline" style="display:none">@Html.DropDownList("attSrchFld", (IEnumerable<SelectListItem>) ViewBag.AttachFlds, "")</span>
    <input type="submit" name="submitSrch" id="submitSrch" value="Search" />
    <input type="button" id="clearQry" value="Clear Search" />
 </fieldset>
}
<table class="TableClass">
    @Html.DisplayForModel()
</table>
<div id="div-1" class="toHide">
@Html.AuthorizeActionLink("Optimize Index", "WikiOptimizeIndex", "Search", null, new { target = "_blank" })
@Html.AuthorizeActionLink("Rebuild Index", "WikiRebuildIndex", "Search", null, new { target = "_blank" })
@Html.AuthorizeActionLink("Clear Index", "WikiClearIndex", "Search", null, new { target = "_blank" })
@Html.AuthorizeActionLink("Index Status", "WikiIndexStatus", "Search", null, new { target = "_blank" })</div>

<div id="div-2" class="toHide" style="display:none">
@Html.AuthorizeActionLink("Optimize Index", "AttOptimizeIndex", "Search", null, new { target = "_blank" })
@Html.AuthorizeActionLink("Rebuild Index", "AttRebuildIndex", "Search", null, new { target = "_blank" })
@Html.AuthorizeActionLink("Clear Index", "AttClearIndex", "Search", null, new { target = "_blank" })
@Html.AuthorizeActionLink("Index Status", "AttIndexStatus", "Search", null, new { target = "_blank" })</div>


@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@section Scripts {
    <script type="text/javascript">
        $(document).ready(function () {
            $("#SrchForm").keypress(function (e) {
                kcode = e.keyCode || e.charCode
                if (kcode == 13) {
                    var defaultbtn = $(this).attr("DefaultButton");
                    $("#" + defaultbtn).click();
                    return false;
                }
            });
            $("[name=toggler]").click(function () {
                $('.toHide').hide();
                $("#blk-" + $(this).val()).show('slow');
                $("#div-" + $(this).val()).show('slow');
            });
            $("#clearQry").click(function () {
                $("#txtSrchTerm").val("");
            });
        });
    </script>
}

